package cn.itrip.search.controller;
import cn.itrip.beans.dtos.Dto;
import cn.itrip.common.EmptyUtils;
import cn.itrip.common.PageBean;
import cn.itrip.search.service.SearchService;
import cn.itrip.common.DtoUtils;
import cn.itrip.search.vo.HotelParam;
import io.swagger.annotations.ApiOperation;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.springframework.web.bind.annotation.*;
import cn.itrip.search.vo.ItripHoteVo;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/hotellist")
public class SearchController{
    @Resource
    private SearchService searchService;

    /***
     * 搜索酒店分页
     *
     * @param param
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "查询酒店分页", httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "查询酒店分页(用于查询酒店列表)" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码: </p>" +
            "<p>20001: 系统异常,获取失败</p>" +
            "<p>20002: 目的地不能为空</p>")
    @RequestMapping(value = "/searchItripHotelPage", produces = "application/json", method = RequestMethod.POST)
    @ResponseBody
    public Dto searchItripHotelPage(@RequestBody HotelParam param){

        try {

              PageBean  pageBean = new PageBean();
                pageBean.setCurPage(param.getPageNo() == null ? 1:param.getPageNo());
                pageBean.setPageSize(2);

            searchService.searchItripHotelPage(param,pageBean);
            return DtoUtils.returnDataSuccess(pageBean);
        }catch (Exception e){
            return DtoUtils.returnFail(e.getMessage(),"50001");
        }
    }

    @ApiOperation(value = "根据热门城市查询酒店", httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据热门城市查询酒店" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码: </p>" +
            "<p>20003: 系统异常,获取失败</p>" +
            "<p>20004: 城市id不能为空</p>")
    @PostMapping("/searchItripHotelListByHotCity")
    @ResponseBody
    public Dto searchItripHotelListByHotCity(@RequestBody Map param){
        try {
            List<ItripHoteVo> list = searchService.searchItripHotelListByHotCity(param.get("cityId")+"",(Integer)param.get("count"));
            return DtoUtils.returnDataSuccess(list);
        } catch (Exception e) {
            return DtoUtils.returnFail(e.getMessage(),"50001");
        }
    }

}
